<?php

namespace app\admin\validate;

use think\Validate;

class AdminValidate extends Validate
{
    protected $rule = [
        'nickname' => 'max:30',
        'username' => 'require|unique:admin|max:30',
        'avatar' => 'max:255',
        'password' => 'require|confirm',
        'roles' => 'require|array',
        'remark' => 'max:255',
        'status' => 'require|in:0,1',
    ];


    protected $message = [
        'id.require' => '非法请求',
        'id.integer' => '非法请求',
        'nickname' => '昵称过长',
        'avatar' => '非法的头像!',
        'username.require' => '用户名不能为空',
        'username.unique' => '用户已存在!',
        'password.require' => '密码不能为空!',
        'password.confirm' => '密码两次输入不一致!',
        'roles.require' => '请选择角色',
        'remark.max' => '备注过长!',
        'status.in' => '无效的状态值!',
    ];

    public function sceneSwitch()
    {
        return $this->only(['id','status'])
                    ->append('id', 'require|integer');
                   
    }

    public function sceneMe()
    {
        return $this->only(['id','nickname','avatar','password'])
                    ->append('id', 'require|integer')
                    ->remove('password','require');
    }

    public function sceneEdit()
    {
    	return $this->only(['id','nickname','username','password','roles','remake','status'])
                    ->append('id', 'require|integer');
            
    }   
}